home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1997 #1 / Amiga Plus CD - 1997 - No. 01.iso / pd / programmierung / arexxport_dev / demo / demo.c < prev    next >
C/C++ Source or Header  |  1996-05-02  |  4KB  |  125 lines

  1. /*
  2. ** Demo arexx test file
  3. ** Link with arexxport.lib
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <exec/types.h>
  8. #include <exec/lists.h>
  9. #include <dos/dos.h>
  10. #include <rexx/storage.h>
  11. #include <rexx/rxslib.h>
  12. #include <rexx/arexxport.h>
  13.  
  14. #include <clib/arexxport_protos.h>
  15. #include <clib/exec_protos.h>
  16.  
  17. struct Library *ArexxPortBase = NULL;
  18.  
  19. void a_Load( struct ArexxMsg *amsg );
  20. void a_Saveas( struct ArexxMsg *amsg );
  21. void a_Quit( struct ArexxMsg *amsg );
  22.  
  23. /* Function Table */
  24.  struct ArexxFunction comtable[] = {
  25.     {"load", &a_Load, "FILE"},
  26.     {"saveas", &a_Saveas, "FILE,OVERWRITE/S,VAR"},
  27.     {"quit", &a_Quit, "FORCE/S"},
  28.     {"fault", &ReturnArexxError, "VAR"},
  29.     {NULL, NULL, NULL}
  30. };
  31.  
  32. void main() {
  33.  
  34.     if(!(ArexxPortBase = OpenLibrary("arexxport.library", 37 ))) {
  35.         printf("Unable to open lib.\n");
  36.         return;
  37.     }
  38.  
  39.     printf("Lib open\n");
  40.  
  41.     /* Open a port */
  42.     struct ArexxPort *port1, *port2, *port3;
  43.     port1 = OpenArexxPort("TEST_PORT",
  44.                     ARLT_COMMANDS, comtable,
  45.                     ARLT_CONSOLE, "con:0/0/640/50",
  46.                     ARLT_LASTERROR, NULL,
  47.                     TAG_END);
  48.  
  49.     /* Open two more and chain them */
  50.     port2 = OpenArexxPort("TEST_PORT", ARLT_CHAIN, port1, TAG_END);
  51.     port3 = OpenArexxPort("TEST_PORT", ARLT_CHAIN, port1, TAG_END);
  52.  
  53.     if( port1 && port2 && port3 ) {
  54.         printf("Ports Open - Control D to exit.\n");
  55.         /* Launch a Macro  */
  56.         printf("Return from launch %lx\n", LaunchArexx( port1, "test.rexx", TRUE, 4 ) );
  57.         BOOL done = FALSE;
  58.  
  59.         while( ! done ) {
  60.  
  61.             ULONG signal = Wait( (1L<<(AREXX_SIGBIT(port1))) | SIGBREAKF_CTRL_D );
  62.  
  63.             if(signal & SIGBREAKF_CTRL_D) {
  64.                 if( ArexxMacroPending( port1 ) ) {
  65.                     puts( "Cannot quit - all macros haven't returned yet" );
  66.                 } else {
  67.                     done = TRUE;
  68.                 }
  69.             } else {
  70.  
  71.                 /* Deal with arexx messages */
  72.                 struct ArexxMsg *amsg;
  73.                 while( amsg = CheckArexxPort( port1 ) ) {
  74.  
  75.                     if(amsg->Type == AREXX_COMMAND) {
  76.                         void (*target)( struct ArexxMsg *msg ) = (void *)amsg->User_Data;
  77.                         target( amsg );
  78.                     }
  79.                     else if(amsg->Type == AREXX_MESSAGE) {
  80.                         printf("Message Received. Macro UserData = %u\n", amsg->User_Data);
  81.                         if( amsg->arg[0] )  printf(" Arg[0] = %s\n", amsg->arg[0] );
  82.                         if( amsg->arg[1] )  printf(" Arg[1] = %s\n", amsg->arg[1] );
  83.                         if( amsg->arg[2] )  printf(" Arg[2] = %s\n", amsg->arg[2] );
  84.                     }
  85.                     ReplyArexxPort( amsg );
  86.                 }
  87.             }
  88.         }
  89.     }
  90.  
  91.     /* Shut Ports */
  92.     if( port1 )     CloseArexxPort( port1 );
  93.     if( port2 )     CloseArexxPort( port2 );
  94.     if( port3 )     CloseArexxPort( port3 );
  95.  
  96.     printf("Ports Closed\n");
  97.     CloseLibrary( ArexxPortBase );
  98.  
  99.     printf("All done\n");
  100. }
  101.  
  102. void a_Load( struct ArexxMsg *amsg ) {
  103.     printf("Load command Received at port %s\n", amsg->port->PortName );
  104.     if( amsg->arg[0] )     printf("File = %s" , amsg->arg[0] );
  105.     puts("");
  106. }
  107.  
  108. void a_Saveas( struct ArexxMsg *amsg ) {
  109.     printf("Saveas command Received at port %s\n", amsg->port->PortName );
  110.     if( amsg->arg[0] )     printf("File = %s" , amsg->arg[0] );
  111.     if( amsg->arg[1] )     printf(" 'Overwrite'" );
  112.     puts("");
  113.     puts("Returning 'hello world'" );
  114.     SetArexxReturnVar( amsg, 0, "Hello World", (STRPTR)amsg->arg[2] );
  115. }
  116.  
  117. void a_Quit( struct ArexxMsg *amsg ) {
  118.     printf( "Quit command Received at port %s\n", amsg->port->PortName );
  119.     if( amsg->arg[0] )     printf("Force" );
  120.     puts("");
  121. }
  122.  
  123.  
  124.  
  125.